<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>添加常用联系人</title>
    <link rel="stylesheet" href="../../../css/aui.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav fixed " style="background-color:#3cb0d6;" id="header">
        <a class="aui-pull-left aui-btn">
            <span class="aui-iconfont aui-icon-left" onclick="closeWin()"></span>
        </a>
        <div class="aui-title">常用联系人</div>
    </header>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list">
            <!--<li class="aui-list-header">带有图标的表单</li>-->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-my"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入常用联系人姓名" class="name">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-phone"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="number" placeholder="请输入常用联系人手机号码" class="phone">
                    </div>
                </div>
            </li>
        </ul>
        <div class="aui-btn aui-btn-success aui-btn-block aui-btn-sm submit" style="margin:.7rem auto;width:50%;background:#3cb0d6;" onclick="contact_add()">提交</div>
    </div>
</body>
<script type="text/javascript" src="../../../script/aui/api.js"></script>
<script type="text/javascript" src="../../../script/aui/aui-toast.js"></script>
<script type="text/javascript" src="../../../script/extend/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../../script/config.js"></script>
<script type="text/javascript" src="../../../script/common.js"></script>

<script>
    apiready = function(){
        api.parseTapmode();
        //设置沉浸式
        var header = $api.byId('header');
        $api.fixStatusBar(header);
    }
    function contact_add() {
        var toast = new auiToast({});
        var param = {};

        var name = $('.name').val(),
            mobile = $('.phone').val();
        if (!$.trim(name)) {
            $toast('姓名不能为空');
            return false;
        }
        if (!isPhoneNo(mobile)) {
            $toast('手机号码格式不正确');
            return false;
        }
        param.url =  Config.common.addContact;
        param.data =  {
            contact_name: name,
            contact_mobile: mobile
        };
        ajax(param, function(ret) {
            if (ret.code == 1) {
                $toast('添加成功');
                api.sendEvent({
                    name: 'addContactEvt'
                });
                api.closeWin();
            }else {
                $toast(ret.msg);
            }
        });
    }

    function isPhoneNo(phone) {
        var pattern = /^1[34578]\d{9}$/;
        return pattern.test(phone);
    }
</script>

</html>
